package com.CNMedical.web.controller.system.applet;


import com.CNMedical.common.annotation.Anonymous;
import com.CNMedical.common.core.controller.BaseController;
import com.CNMedical.common.core.domain.R;
import com.CNMedical.system.domain.entity.*;
import com.CNMedical.system.domain.vo.AppletKnowledgeCommentVO;
import com.CNMedical.system.domain.vo.AppletKnowledgeVO;
import com.CNMedical.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 知识相关Controller
 *
 * @author tang
 * @date 2023-03-29
 */
@Api(tags = "知识相关接口")
@Anonymous
@RestController
@RequestMapping("/applet/knowledge")
public class KnowledgeController extends BaseController {

    @Resource
    private IAppletKnowledgeTypeService iAppletKnowledgeTypeService;

    @Resource
    private IAppletKnowledgeService appletKnowledgeService;

    @Resource
    private IAppletKnowledgeCommentService iAppletKnowledgeCommentService;

    @Resource
    private IAppletKnowledgeCollectService iAppletKnowledgeCollectService;

    @Resource
    private IAppletLearningHistoryService appletLearningHistoryService;


    /**
     * 获取所有知识类别
     *
     * @date 2023-03-30
     */
    @ApiOperation("获取所有知识类别")
    @GetMapping("/getAllKnowledgeType")
    public R<List<AppletKnowledgeType>> getAllKnowledgeType() {
        List<AppletKnowledgeType> appletKnowledgeTypeList = iAppletKnowledgeTypeService.getAllKnowledgeType();
        return R.ok(appletKnowledgeTypeList);
    }

    /**
     * 搜索
     *
     * @date 2023-03-30
     */
    @ApiOperation("搜索知识")
    @GetMapping("/searchKnowLedge")
    public R<List<AppletKnowledge>> searchKnowLedge(@RequestParam(required = false) String content) {
        List<AppletKnowledge> appletKnowledgeList = appletKnowledgeService.searchKnowLedge(content);
        return R.ok(appletKnowledgeList);
    }

    /**
     * 获取知识详情
     *
     * @date 2023-03-30
     */
    @ApiOperation("获取知识详情")
    @GetMapping("/getKnowLedgeDetail/{knowledgeId}")
    public R<AppletKnowledgeVO> getKnowLedgeDetail(@PathVariable String knowledgeId, @RequestParam(required = false) String userId) {
        AppletKnowledgeVO appletKnowledgeVO = appletKnowledgeService.appGetKnowledgeDetail(knowledgeId,userId);
        return R.ok(appletKnowledgeVO);
    }

    /**
     * 获取知识评论
     *
     * @date 2023-03-30
     */
    @ApiOperation("获取知识评论")
    @GetMapping("/getKnowLedgeCommentByKnowledgeId/{knowledgeId}")
    public R<List<AppletKnowledgeCommentVO>> getKnowledgeComment(@PathVariable String knowledgeId) {
        List<AppletKnowledgeCommentVO> appletKnowledgeCommentList = iAppletKnowledgeCommentService.getKnowLedgeCommentByKnowledgeId(knowledgeId);
        return R.ok(appletKnowledgeCommentList);
    }

    /**
     * 知识收藏
     *
     * @date 2023-03-30
     */
    @ApiOperation("知识收藏")
    @PostMapping("/addKnowledgeCollect")
    public R addKnowledgeCollect(@RequestBody AppletKnowledgeCollect appletKnowledgeCollect) {
        return iAppletKnowledgeCollectService.addKnowledgeCollect(appletKnowledgeCollect);
    }

    /**
     * 知识取消收藏
     *
     * @date 2023-03-30
     */
    @ApiOperation("知识取消收藏")
    @PostMapping("/cancelKnowledgeCollect")
    public R cancelKnowledgeCollect(@RequestParam("knowledgeId") String knowledgeId, @RequestParam("userId") String userId) {
        return R.ok(iAppletKnowledgeCollectService.cancelKnowledgeCollect(knowledgeId,userId));
    }

    /**
     * 获取知识类型下的所有知识
     *
     * @date 2023-03-30
     */
    @ApiOperation("获取知识类型下的所有知识")
    @GetMapping("/getKnowledgeByType/{typeId}")
    public R<List<AppletKnowledge>> getKnowledgeByType(@PathVariable String typeId) {
        return R.ok(appletKnowledgeService.selectAppletKnowledgeByTypeId(typeId));
    }

    /**
     * 新增知识留言
     */
    @ApiOperation("用户添加知识留言")
    @PostMapping("/addCommentKnowledge")
    public R commentKnowledge(@RequestBody AppletKnowledgeComment appletKnowledgeComment)
    {
        return R.ok(iAppletKnowledgeCommentService.insertAppletKnowledgeComment(appletKnowledgeComment));
    }

    /**
     * 删除知识留言
     */
    @ApiOperation("用户删除知识留言")
    @DeleteMapping("/deleteCommentKnowledge/{ids}")
    public R deleteCommentKnowledge(@RequestBody AppletKnowledgeComment appletKnowledgeComment)
    {
        return R.ok(iAppletKnowledgeCommentService.deleteCommentKnowledge(appletKnowledgeComment));
    }

    /**
     * 开始学习知识
     */
    @ApiOperation("开始学习知识")
    @PostMapping("/startLearningKnowledge")
    public R startLearningKnowledge(@RequestBody AppletLearningHistory appletLearningHistory)
    {
        return R.ok(appletLearningHistoryService.addLearningHistory(appletLearningHistory));
    }

    /**
     * 删除学习记录
     */
    @ApiOperation("删除学习记录")
    @DeleteMapping("/deleteLearningHistory/{ids}")
    public R deleteLearningHistory(@PathVariable Long[] ids)
    {
        return R.ok(appletLearningHistoryService.deleteAppletLearningHistoryByIds(ids));
    }

    /**
     * 获取学习记录列表
     */
    @ApiOperation("获取学习记录列表")
    @GetMapping("/getLearningHistory/{userId}")
    public R deleteLearningHistory(@PathVariable String userId)
    {
        return R.ok(appletLearningHistoryService.getLearningHistoryByUserId(userId));
    }

    /**
     * 知识收藏列表
     */
    @ApiOperation("知识收藏列表")
    @PostMapping("/getKnowledgeCollectListByUserId/{userId}")
    public R getKnowledgeCollectListByUserId(@PathVariable String userId)
    {
        return R.ok(iAppletKnowledgeCollectService.getKnowledgeCollectListByUserId(userId));
    }
}
